<template>
  <t-tabs v-model="value" size="medium">
    <t-tab-panel :class="[reviewOpen?'tab-full-panel':'tab-panel']" value="1" label="基本信息">
      <t-form labelWidth="120px" :colon="true">
        <t-row style="align-items: stretch" :gutter="14">
          <t-col :span="12">
            <t-card class="step-card" size="small" title="基本信息">
              <t-row>
                <t-col :span="6">
                  <t-form-item label="标准名称" name="name">
                    {{data.name}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="联系人姓名" name="linkMan">
                    {{ data.linkMan }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="标准编号" name="projectNum">
                    {{ data.projectNum  || '暂未分配' }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="联系人电话" name="linkWay">
                    {{ data.linkWay }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="标准公告号" name="publishNum">
                    {{data.publishNum}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="制定或修改" name="formulateType">
                    {{ data.formulateType | filterByDict(dict.type.formulate_type) }}
                  </t-form-item>
                </t-col>
                <t-col :span="6" v-if="data.formulateType!=='1'">
                <t-form-item ref="reviseNum"  label="被修订标准号" name="reviseNum">
                  {{ data.reviseNum }}
                </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="代替标准号" name="replaceNum">
                    {{data.replaceNum}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="主管单位" name="manageDeptId">
                    {{data.manageDeptName}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="标准性质" name="standardProperty">
                    {{data.standardProperty | filterByDict(dict.type.standard_property)}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="提出时间" name="completeDate">
                    {{ data.completeDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="标准类别" name="standardCategory">
                    {{ data.standardCategory | filterByDict(dict.type.standard_category) }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="发布时间" name="publishDate">
                    {{ data.publishDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="标准体系" name="systemId">
                    {{ data.systemName }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item label="实施时间" name="implDate">
                    {{ data.implDate }}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item  label="承担单位" >
                    {{data.declareDeptName}}
                  </t-form-item>
                </t-col>
                <t-col :span="6">
                  <t-form-item  label="关键词" name="keyWord">
                    {{ data.keyWord }}
                  </t-form-item>
                </t-col>
              </t-row>

            </t-card>
          </t-col>
        </t-row>
      </t-form>
    </t-tab-panel>
    <t-tab-panel :class="[reviewOpen?'tab-full-panel':'tab-panel']" value="3" label="起草单位">
      <t-form labelWidth="140px" >
        <t-row style="align-items: stretch;">
          <t-col :span="12">
            <standard-company ref="standard-company" v-model="data.draftUnits" :editOpen="false"></standard-company>
          </t-col>
        </t-row>
      </t-form>
    </t-tab-panel>
      <t-tab-panel  :class="[reviewOpen?'tab-full-panel':'tab-panel']" value="4" label="起草小组成员">
        <t-form labelWidth="140px" >
          <t-row style="align-items: stretch;">
            <t-col :span="12">
              <t-card class="step-card" size="small" title="起草小组成员">
                <member-list v-model="data.draftPersons"
                             :editOpen="false" ></member-list>
              </t-card>
            </t-col>
          </t-row>
        </t-form>
      </t-tab-panel>
    <t-tab-panel :class="[reviewOpen?'tab-full-panel':'tab-panel']" value="5" label="附件">
      <t-form labelWidth="140px" >
        <t-row style="align-items: stretch;">
          <t-col :span="12">
            <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
              <template #id="{row, rowIndex}">
                {{ rowIndex+1 }}
              </template>
              <template  #op="{row}">
                <div v-for="(item,index) in row.fileLists" :key="index">
                  <a class="t-button-link" target="_blank" :href="item.url" >
                    {{item.name}}
                  </a>
                </div>
              </template>
            </t-table>
          </t-col>
        </t-row>
      </t-form>
    </t-tab-panel>
  </t-tabs>
</template>

<script>

import {getFiles} from "@/api/common";
import MemberList from "../../../components/member-list.vue";
import standardCompany from "@/pages/bzh/standard/components/standard-company.vue";

export default {
  name: "standard-detail",
  dicts:["formulate_type","standard_category","standard_property","prof_tit","sys_user_sex","education","degree"],
  components: {
    standardCompany,
    MemberList
  },
  props: {
    objId: [String,Number],
    reviewOpen: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      standardSystemOptions:[],
      value:"1",
      deptMenuOptions:[],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },
        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      projectFileData: [
        {
          id: 1,
          c1: "立项阶段",
          c2: "否",
          moduleKey: "bzhLXJD",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 2,
          c1: "报审阶段",
          c2: "否",
          moduleKey: "bzhBSJD",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 3,
          c1: "报批阶段",
          c2: "否",
          moduleKey: "bzhBPJD",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 4,
          c1: "发布阶段",
          c2: "否",
          moduleKey: "bzhFBJD",
          fileIds: [],
          fileLists: [],
        },
        {
          id: 5,
          c1: "贯标附件",
          c2: "否",
          moduleKey: "bzhGBFJ",
          fileIds: [],
          fileLists: [],
        },
      ],
      tabValue:"1",
      profTitOptions:[],
      data: {
        draftUnits:[],
        draftPersons: []
      },
    }
  },

  created() {
    this.getObj();
    // this.getDeptTreeSelect();
    // this.getStandardSystemTree()
  },
  methods: {
    getStandardSystemTree(){
      return this.$api.bzh.standard.standardSystemTree().then(response => {
        this.standardSystemOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect(){
      return this.$api.system.dept.treeSelectAllIn().then(response=>{
        this.deptMenuOptions = response.data
      }).catch(e=>{
        this.$message.error(e.toString())
      })
    },
    getObj(){
      this.$api.bzh.register.getByLocalId(this.objId).then(response=>{
        this.data = response.data;
        getFiles(response.data.id).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val,index)=>{
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      })
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel{
  padding: 10px;
}
.tab-panel{
  height: calc(65vh - 64px);
  overflow: scroll;
}
.tab-full-panel{
  height: calc(80vh - 64px);
  overflow: scroll;
}
.t-form__item{
  margin-bottom:6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}
</style>
